#define _GNU_SOURCE
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>

int cal_sqr(int num){
    sleep(1);
    return num*num;
}

int main(void){
    int num[5]={1,2,3,4,5};
    int sum[5]={0};
    int sum_all=0;
    struct timeval tv_start,tv_end;
    gettimeofday(&tv_start,NULL);
    for(int i=0;i<5;i++){
        sum[i]=cal_sqr(num[i]);
    }
    gettimeofday(&tv_end,NULL);
    printf("计算平方和耗时：%lds\n",tv_end.tv_sec-tv_start.tv_sec);
    for(int i=0;i<5;i++){
        sum_all+=sum[i];
    }
    printf("平方和是：%d\n",sum_all);
    return 0;
}
